﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace GirisSayfasi.Class
{
    class kullanici
    {

        public int kullaniciID { get; set; }
        public string kullaniciadi { get; set; }
        public string parola { get; set; }
        public string isimsoyisim { get; set; }
        public string gorev { get; set; }
        public DateTime dogumtarihi { get; set; }
        public int durum { get; set; }
        public int rollID { get; set; }
        public string email { get; set; }
        public string gsm { get; set; }
        public string tckimlik { get; set; }



        public bool kullaniciekle()
        {

            try
            {

                SqlConnection sqlcon = Connection.baglan2;
                SqlCommand sqlcmd = new SqlCommand("insert into tblKullanicilar (kullaniciadi,parola,isimsoyisim,gorev,dogumtarihi,durum,rollID,email,gsm,tckimlik) values (@kullaniciadi,@parola,@isimsoyisim,@gorev,@dogumtarihi,@durum,@rollID,@email,@gsm,@tckimlik)", sqlcon);
                sqlcmd.Parameters.AddWithValue("@kullaniciadi", kullaniciadi);
                sqlcmd.Parameters.AddWithValue("@parola", parola);
                sqlcmd.Parameters.AddWithValue("@isimsoyisim", isimsoyisim);
                sqlcmd.Parameters.AddWithValue("@gorev", gorev);
                sqlcmd.Parameters.AddWithValue("@dogumtarihi", dogumtarihi);
                sqlcmd.Parameters.AddWithValue("@durum", durum);
                sqlcmd.Parameters.AddWithValue("@rollID", rollID);
                sqlcmd.Parameters.AddWithValue("@email", email);
                sqlcmd.Parameters.AddWithValue("@gsm", gsm);
                sqlcmd.Parameters.AddWithValue("@tckimlik", tckimlik);


                sqlcon.Open();

                sqlcmd.ExecuteNonQuery();


                sqlcon.Close();

                return true;

            }
            catch (Exception)
            {

                return false;
            }
          





        }


        public void kullanicigiris()
        {

            SqlConnection sqlcon = Connection.baglan2;
            SqlCommand sqlcmd = new SqlCommand("select * from tblKullanicilar where kullaniciadi=@kid and parola=@pid", sqlcon);
            sqlcmd.Parameters.AddWithValue("@kid",kullaniciadi);
            sqlcmd.Parameters.AddWithValue("@pid",parola);

            sqlcon.Open();

            SqlDataReader sdr = sqlcmd.ExecuteReader();

            while (sdr.Read()) ;
            {
                rollID = Convert.ToInt32(sdr["rollID"]);
                kullaniciID = Convert.ToInt32(sdr["kullaniciID"]);
            }

            sqlcon.Close();
        
        }





    }
}
